	/*加号*/
	function add(obj){
		var orderid = $('#orderid').val();
         var setmeal=  $(obj).parent().find('.stemeals').val();
         var detail_id=$(obj).parent().find('.detail_id').val();
         var stype=1;
         $.post("addminus", {orderid: orderid,setmeal: setmeal,stype:stype,detail_id:detail_id}, function (date) {
             var data = date.msg.data;
             var pay = date.msg.pay;
             $('.num').html(pay.num);
             $('.all').html(pay.all_money);
             $('#vip').val(pay.vip);
             $('.orderid').html('<input class="am-text-right" type="text" value="'+pay.orderid+'" style="background: transparent;border:none;">'+'<input type="hidden" id="orderid" value="' + pay.orderid + '">');
             var src = '';
             $.each(data, function (k, val) {
                 var k=k+1;
                 src += '<dl class="am-padding-top-xs am-padding-bottom-xs am-padding-left-sm ">' +
                     '<dt class="dt-h font-z">' +
                     k+
                     val.g_goodsname + '(' + val.format + ')' +
                     '</dt>'+
                     '<div class="am-input-group am-fr">'+
                     '<span class="am-input-group-label minus" onclick="javascript:minus(this)">-'+
                     '</span>'+
                     '<input type="hidden"  class="am-form-field detail_id" value="'+
                     val.id+
                     '">'+
                     '<input type="hidden"  class="am-form-field stemeals" value="'+
                     val.stemeal+
                     '">'+
                     '<input type="hidden"  class="am-form-field nature" value="'+
                     val.nature+
                     '">'+
                     '<input type="text" readonly="readonly" class="am-form-field" value="'+
                     val.count+
                     '">'+
                     '<span class="am-input-group-label add" onclick="javascript:add(this)">+'+
                     '</span>'+
                     '</div>'+
                     '<input type="hidden"  class="am-form-field ordid" value="'+
                     val.orderid+
                     '">'+
                     '<dd>'+
                     '<div class="am-u-md-6 am-u-lg-6 am-padding-left-0 left-w ">'+
                     '<input type="hidden"  class="am-form-field detail_id" value="'+
                     val.id+
                     '">'+
                     '<div class="am-link-muted am-text-xs font-z">单价：￥'+
                     val.money +
                     '</div>'+
                     '<div class="am-text-danger am-text-xs font-z ">小计：￥<span class="ipt1" style="display: inline;cursor:pointer;color:green;">'+
                     val.total +'</span>'+
                     '<input class="ipt2" style="display:none;width:100%;border:1px solid red;width:40px;" maxlength="10"/><input class="ipt3" type="hidden" value="'+val.total+'"/>'+
                     '</div>'+
                     '</div>'+
                     '<div class="am-u-md-6 am-u-lg-6 am-padding-right-0">'+
                     '</div>'+
                     '<div class="clear"></div>'+
                     '<div class="am-u-md-6 am-u-lg-6 am-padding-left-0 left-w ss">'+
                     '<div class="flo-l font-z wendu">'+
                     '<input type="hidden"  class="am-form-field detail_id" value="'+
                     val.id+
                     '">'+
                     '<input type="hidden"  class="am-form-field goodid" value="'+
                     val.goodsid+
                     '">'+
                     '<a class="am-btn am-btn-warning am-radius am-margin-right-sm nature" herf="#">口味('+
                     val.naturename+
                     ')</a>'+
                     '<a class="am-btn am-btn-warning am-radius am-margin-right-sm edit" herf="#">改价'+
                     '</a>'+
                     '</div>'+
                     '</div>'+
                     '</dd>' +
                     '</dl>'
                 $('#cart').html(src);
             })
         }, 'json');
	}
	/*减号*/
	function minus(obj){
		var orderid = $('#orderid').val();
        var setmeal=  $(obj).parent().find('.stemeals').val();
        var detail_id=$(obj).parent().find('.detail_id').val();
        var stype=0;
        $.post("addminus", {orderid: orderid,setmeal: setmeal,stype:stype,detail_id:detail_id}, function (date) {
            var data = date.msg.data;
            var pay = date.msg.pay;
            if(data == '')
            {
                var src = '';
                $('.num').html(src);
                $('.all').html(src);
                $('.orderid').html(  '<input type="hidden" id="orderid" value="">');
                $('#cart').html(src);
                $('#vip').val(src);
            }else{
                $('.num').html(pay.num);
                $('.all').html(pay.all_money);
                $('#vip').val(pay.vip);
                $('.orderid').html('<input class="am-text-right" type="text" value="'+pay.orderid+'" style="background: transparent;border:none;">'+'<input type="hidden" id="orderid" value="' + pay.orderid + '">');
                var src = '';
                $.each(data, function (k, val) {
                    var k=k+1;
                    src += '<dl class="am-padding-top-xs am-padding-bottom-xs am-padding-left-sm ">' +
                        '<dt class="dt-h font-z">' +
                        k+
                        val.g_goodsname + '(' + val.format + ')' +
                        '</dt>'+
                        '<div class="am-input-group am-fr">'+
                        '<span class="am-input-group-label minus" onclick="javascript:minus(this)">-'+
                        '</span>'+
                        '<input type="hidden"  class="am-form-field detail_id" value="'+
                        val.id+
                        '">'+
                        '<input type="hidden"  class="am-form-field stemeals" value="'+
                        val.stemeal+
                        '">'+
                        '<input type="hidden"  class="am-form-field nature" value="'+
                        val.nature+
                        '">'+
                        '<input type="text" readonly="readonly" class="am-form-field" value="'+
                        val.count+
                        '">'+
                        '<span class="am-input-group-label add" onclick="javascript:add(this)">+'+
                        '</span>'+
                        '</div>'+
                        '<input type="hidden"  class="am-form-field ordid" value="'+
                        val.orderid+
                        '">'+
                        '<dd>'+
                        '<div class="am-u-md-6 am-u-lg-6 am-padding-left-0 left-w ">'+
                        '<input type="hidden"  class="am-form-field detail_id" value="'+
                        val.id+
                        '">'+
                        '<div class="am-link-muted am-text-xs font-z">单价：￥'+
                        val.money +
                        '</div>'+
                        '<div class="am-text-danger am-text-xs font-z ">小计：￥<span class="ipt1" style="display: inline;cursor:pointer;color:green;">'+
                        val.total +'</span>'+
                        '<input class="ipt2" style="display:none;width:100%;border:1px solid red;width:100px;" maxlength="10"/><input class="ipt3" type="hidden" value="'+val.total+'"/>'+
                        '</div>'+
                        '</div>'+
                        '<div class="am-u-md-6 am-u-lg-6 am-padding-right-0">'+
                        '</div>'+
                        '<div class="clear"></div>'+
                        '<div class="am-u-md-6 am-u-lg-6 am-padding-left-0 left-w ss">'+
                        '<div class="flo-l font-z wendu">'+
                        '<input type="hidden"  class="am-form-field detail_id" value="'+
                        val.id+
                        '">'+
                        '<input type="hidden"  class="am-form-field goodid" value="'+
                        val.goodsid+
                        '">'+
                        '<a class="am-btn am-btn-warning am-radius am-margin-right-sm nature" herf="#">口味('+
                        val.naturename+
                        ')</a>'+
                        '<a class="am-btn am-btn-warning am-radius am-margin-right-sm edit" herf="#">改价'+
                        '</a>'+
                        '</div>'+
                        '</div>'+
                        '</dd>' +
                        '</dl>'
                    $('#cart').html(src);
                })
            }

        }, 'json');
	}
	

$(function() {
    /*
    * 添加商品(单品)
    * */
    $('.show').on('click','.adds',function () {
        var id = $(this).find('.goods_id').val();
        var setmeal = $(this).find('.stemeal').val();
        var orderid = $('#orderid').val();
        var nature=0;
        $.post("cart", {id: id, orderid: orderid,setmeal: setmeal,nature:nature}, function (date) {
            var data = date.msg.data;
            var pay = date.msg.pay;
            $('.num').html(pay.num);
            $('.all').html(pay.all_money);
            $('#vip').val(pay.vip);
            $('.orderid').html('<input class="am-text-right" type="text" value="'+pay.orderid+'" style="background: transparent;border:none;">'+'<input type="hidden" id="orderid" value="' + pay.orderid + '">');
            var src = '';
            $.each(data, function (k, val) {
                var k=k+1;
                src += '<dl class="am-padding-top-xs am-padding-bottom-xs am-padding-left-sm ">' +
                    '<dt class="dt-h font-z">' +
                     k+
                     val.g_goodsname + '(' + val.format + ')' +
                    '</dt>'+
                    '<div class="am-input-group am-fr">'+
                    '<span class="am-input-group-label minus" onclick="javascript:minus(this)">-'+
                    '</span>'+
                    '<input type="hidden"  class="am-form-field detail_id" value="'+
                    val.id+
                    '">'+
                    '<input type="hidden"  class="am-form-field stemeals" value="'+
                    val.stemeal+
                    '">'+
                    '<input type="hidden"  class="am-form-field nature" value="'+
                    val.nature+
                    '">'+
                    '<input type="text" readonly="readonly" class="am-form-field" value="'+
                    val.count+
                    '">'+
                    '<span  class="am-input-group-label add" onclick="javascript:add(this)">+'+
                    '</span>'+
                    '</div>'+
                    '<input type="hidden"  class="am-form-field ordid" value="'+
                     val.orderid+
                    '">'+
                    '<dd>'+
                    '<div class="am-u-md-6 am-u-lg-6 am-padding-left-0 left-w ">'+
                    '<input type="hidden"  class="am-form-field detail_id" value="'+
                    val.id+
                    '">'+
                    '<div class="am-link-muted am-text-xs font-z">单价：￥'+
                    val.money +
                    '</div>'+
                    '<div class="am-text-danger am-text-xs font-z">小计：￥<span class="ipt1" style="display: inline;cursor:pointer;color:green;">'+
                        val.total +'</span>'+
                        '<input class="ipt2" style="display:none;width:100%;border:1px solid red;width:100px;" maxlength="10"/><input class="ipt3" type="hidden" value="'+val.total+'"/>'+
                    '</div>'+
                    '</div>'+
                    '<div class="am-u-md-6 am-u-lg-6 am-padding-right-0">'+
                    '</div>'+
                    '<div class="clear"></div>'+
                    '<div class="am-u-md-6 am-u-lg-6 am-padding-left-0 left-w ss">'+
                    '<div class="flo-l font-z wendu">'+
                    '<input type="hidden"  class="am-form-field detail_id" value="'+
                    val.id+
                    '">'+
                    '<input type="hidden"  class="am-form-field goodid" value="'+
                    val.goodsid+
                    '">'+
                    '<a class="am-btn am-btn-warning am-radius am-margin-right-sm nature" herf="#">口味('+
                    val.naturename+
                    ')</a>'+
                    '<a class="am-btn am-btn-warning am-radius am-margin-right-sm edit" herf="#">改价'+
                    '</a>'+
                    '</div>'+
                    '</div>'+
                    '</dd>' +
                    '</dl>'
                $('#cart').html(src);
            })
        }, 'json')
    });
    /*
    * 添加属性
    * */
    $('#cart').on('click','.nature',function(){
        var goodsid=$(this).parent().find('.goodid').val();
        var detail_id=$(this).parent().find('.detail_id').val();
        //自定页
        layer.open({
            type: 2,
            title:'添加商品属性',
            skin: 'layui-layer-demo', //样式类名
            shadeClose: true,
            closeBtn: 0, //不显示关闭按钮
            maxmin: false, //开启最大化最小化按钮
            area: ['50%', '50%'],
            content: 'goods_state?goodsid='+goodsid+'&detail_id='+detail_id//视图路径
        })
    })
    /*
    * 清空
    * */
    $('#clear').click(function()
    {
        var orderid = $('#orderid').val();
        $.post('emptys',{orderid:orderid},function (date) {
            var src="";
            $('.num').html(src);
            $('.all').html(src);
            $('.orderid').html(  '<input type="hidden" id="orderid" value="">');
            $('#cart').html(src);
            $('#vip').val(src);
        },'json');
    })
    /*
    * 关闭打开按钮
    * */
    $('#cart').on('click','.am-padding-left',function(){
        $(this).parent().parent().next().toggleClass('yc');
    })
    /*
    * 挂单
    * */
    $('#puorder').click(function()
    {
        var orderid = $('#orderid').val();
        $.post('updata',{orderid:orderid},function(date){
             if(date.msg == 1)
             {
                 alert('挂单成功');
                 var src='';
                 $('.orderid').html('<input type="hidden" id="orderid" value="">')
                 $('#cart').html(src);
                 $('.all').html(src);
             }else{
                 alert('挂单失败');
             }
        },'json');
    })
    /*
    * 挂单表
    * */
    $('#puorders').click(function () {
        layer.open({
            type: 2,
            title: '商品挂单',
            shadeClose: true,
            shade: false,
            maxmin: false, //开启最大化最小化按钮
            area: ['100%', '100%'],
            content: 'updata'//视图路径
        })
    });
    /*
    *改价
    * */
    $('#cart').on('click','.edit',function () {
        var detail_id=$(this).parent().children('.detail_id').val();
        var orderid = $('#orderid').val();
        layer.open({
            type: 2,
            title: '商品改价',
            shadeClose: true,
            shade: false,
            maxmin: false, //开启最大化最小化按钮
            area: ['100%', '100%'],
            content: 'detail&detail_id='+detail_id+'?order='+orderid//视图路径
        })
    })
})